package com.xmb.wechat.dialog;

import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;

import com.blankj.utilcode.util.ScreenUtils;
import com.xmb.wechat.R;
import com.xmb.wechat.definterface.onGroupTalkStateChooseListener;

import java.util.Objects;

/**
 * @Author lijiangop
 * @CreateTime 2020/4/29 14:55
 */
public class GroupCallStateDialog extends Dialog {
    public GroupCallStateDialog(Context context, onGroupTalkStateChooseListener listener) {
        super(context, R.style.PopupDialog);
        initView(context, listener);
    }

    private void initView(Context context, onGroupTalkStateChooseListener listener) {
        View view = LayoutInflater.from(context).inflate(R.layout.dialog_group_talk_state, null, false);
        view.findViewById(R.id.btn_connecting).setOnClickListener(v -> {
            if (listener != null)
                listener.onStateChoose(0);
            dismiss();
        });
        view.findViewById(R.id.btn_normal).setOnClickListener(v -> {
            if (listener != null)
                listener.onStateChoose(1);
            dismiss();
        });
        view.findViewById(R.id.btn_talking).setOnClickListener(v -> {
            if (listener != null)
                listener.onStateChoose(2);
            dismiss();
        });
        setContentView(view);
        WindowManager.LayoutParams lp = Objects.requireNonNull(getWindow()).getAttributes();
        lp.width = ScreenUtils.getScreenWidth();
        lp.dimAmount = 0.5f;
        lp.width = ScreenUtils.getScreenWidth() * 4 / 5;
        lp.gravity = Gravity.CENTER;
        getWindow().setAttributes(lp);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
    }
}
